package com.ttg.web.controller.common;

import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.TagClassDTO;
import com.ttg.model.dto.TagClassPageDTO;
import com.ttg.model.dto.TagInfoDTO;
import com.ttg.model.dto.TagPageDTO;
import com.ttg.web.service.TagClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * Description： 标签分类
 * Author: chenyou
 * Date: 2025/10/20 17:49
 * Company: ttg
 * Copyright: Copyright (c) 2025
 */
@Slf4j
@Api("标签模块")
@RestController
@RequestMapping("/tagClass")
public class TagClassController {

    @Autowired
    private TagClassService tagClassService;

    @ApiOperation("分页查询")
    @RequestMapping("/pagelist")
    public BaseResult pagelist(@RequestBody(required = false) String data){
        TagClassPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassPageDTO.class);
        return BaseResult.success(tagClassService.pagelist(reqDto));
    }
    @ApiOperation("获取分类")
    @RequestMapping("/getClass")
    public BaseResult getClass(@RequestBody(required = false) String data){
        TagClassDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassDTO.class);
        return BaseResult.success(tagClassService.getClass(reqDto));
    }

    @ApiOperation("添加标签分类")
    @RequestMapping("/add")
    public BaseResult add(@RequestBody(required = false) String data){
        TagClassDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassDTO.class);
        return tagClassService.add(reqDto);
    }

    @ApiOperation("修改标签分类")
    @RequestMapping("/edit")
    public BaseResult edit(@RequestBody(required = false) String data){
        TagClassDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassDTO.class);
        return tagClassService.edit(reqDto);
    }

    @ApiOperation("删除标签分类")
    @RequestMapping("/delete")
    public BaseResult delete(@RequestBody(required = false) String data){
        TagClassDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassDTO.class);
        return tagClassService.delete(reqDto);
    }

    @ApiOperation("标签分类导出")
    @RequestMapping("/export")
    public void export(@RequestBody(required = false) String data, HttpServletResponse response){
        TagClassPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagClassPageDTO.class);
        tagClassService.export(reqDto, response);
    }

}
